package com.example.wisdommanufactor.fragment;

import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.webkit.WebResourceRequest;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;

import com.example.wisdommanufactor.R;

import me.yokeyword.fragmentation.SupportActivity;
import me.yokeyword.fragmentation.SupportHelper;

public class FactoryLightFragment extends BaseFragment {
    private static final String TAG = "FactoryLightFragment";
    WebView mWebView;
    ImageView mIvBack;
    TextView mTvTitle;

    public static void start() {
        FactoryLightFragment factoryLightFragment = new FactoryLightFragment();
        factoryLightFragment.start(factoryLightFragment);
    }

    @Override
    public Object setLayout() {
        return R.layout.factory_light_layout;
    }

    @Override
    public void onBindView(@Nullable Bundle saveInstanceState, View rootView) {
        mWebView = rootView.findViewById(R.id.wv_factory_light);
        mWebView.getSettings().setJavaScriptEnabled(true);
        mWebView.loadUrl("file:///android_asset/factory_light.html");
        mWebView.setWebViewClient(new MyWebViewClient());

        mIvBack = rootView.findViewById(R.id.back);
        mTvTitle = rootView.findViewById(R.id.tv_title);

        mTvTitle.setText("灯光控制");
        initEvent();
    }

    private void initEvent() {
        mIvBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Log.e(TAG, "onClick: "+"BACK" );
                pop();
            }
        });
    }

    private class MyWebViewClient extends WebViewClient {
        @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
            view.loadUrl(request.getUrl().toString());
            return true;
        }
    }

    @Override
    public boolean onBackPressedSupport() {
        return super.onBackPressedSupport();
    }
}
